package com.sanfeng.smbms.controller;

import com.sanfeng.smbms.common.utils.PageUtils;
import com.sanfeng.smbms.common.utils.R;
import com.sanfeng.smbms.entity.StockEntity;
import com.sanfeng.smbms.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Nelson
 * @email Nelson@gmail.com
 * 库存
 * @date 2022-07-03 17:23:57
 */
@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = stockService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public R listAll() {
        List<StockEntity> stockEntities = stockService.queryPage();
        return R.ok().put("page", stockEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{stockid}")
    public R info(@PathVariable("stockid") Integer stockid) {
        StockEntity stock = stockService.getById(stockid);
        return R.ok().put("stock", stock);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StockEntity stock) {
        stockService.save(stock);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StockEntity stock) {
        stockService.updateById(stock);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List stockids) {
        stockService.removeByIds(stockids);
        return R.ok();
    }

}
